package cate.game.stat.item;

import cp.solution.business.pay.PayRecordEntity;
import io.netty.util.concurrent.FastThreadLocal;

import java.util.Optional;

public final class StatPayRecordContext implements AutoCloseable {

    static final FastThreadLocal<PayRecordEntity> LOCAL_STORAGE = new FastThreadLocal<>();

    public StatPayRecordContext(PayRecordEntity entity) {
        LOCAL_STORAGE.set(entity);
    }

    public static Optional<PayRecordEntity> current() {
        return Optional.ofNullable(LOCAL_STORAGE.get());
    }

    @Override
    public void close() throws Exception {
        LOCAL_STORAGE.remove();
    }
}
